﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    class Program
    {
        static char[,] mp = new char[3, 3];
        static int[] record = new int[1000];
        static int game()
        {
            for(int i=0;i<3;i++)
            {
                for(int j=0;j<3;j++)
                {
                    mp[i, j]= ' ';
                }
            }
            for (int i= 0;i<9; i++){
                int x, y;
                Console.WriteLine("{0}|{1}|{2}", mp[0, 0], mp[0, 1], mp[0, 2]);
                Console.WriteLine("-+-+-");
                Console.WriteLine("{0}|{1}|{2}", mp[1, 0], mp[1, 1], mp[1, 2]);
                Console.WriteLine("-+-+-");
                Console.WriteLine("{0}|{1}|{2}", mp[2, 0], mp[2, 1], mp[2, 2]);
                Console.WriteLine("Play{0}\n", (i & 1) + 1);
                Console.WriteLine("输入两个数字换行为分隔符\n");
                x = int.Parse(Console.ReadLine());
                y = int.Parse(Console.ReadLine());
                if ((i & 1) == 0)
                {
                    mp[x - 1, y - 1] = 'X';
                    bool flag = true;
                    for (int j = 0; j < 3; j++)
                    {
                        if (mp[x - 1, j] != 'X')
                        {
                            flag = false;
                        }
                    }
                    if (flag) return 1;
                    flag = true;
                    for (int j = 0; j < 3; j++)
                    {
                        if (mp[j, x - 1] != 'X')
                        {
                            flag = false;
                        }
                    }
                    if (flag) return 1;
                    flag = true;
                    if ( ((x - 1) == 0 && y - 1 == 0) || (x - 1 == 1 && y - 1 == 1) || (x - 1 == 2 && y - 1 == 2)) {
                        for(int j=0;j<3;j++)
                        {
                            if (mp[j, j] != 'X'){
                                flag = false;
                            }
                        }
                        if (flag) return 1;
                    }
                    flag = true;
                    if ((x - 1 == 0 && y - 1 == 2) || (x - 1 == 1 && y - 1 == 1) || (x - 1 == 2 && y - 1 == 0))
                    {
                        for (int j = 0; j < 3; j++)
                        {
                            if (mp[j, 2 - j] != 'X'){
                                flag = false;
                            }
                        }
                        if (flag) return 1;
                    }
                }
                else
                {
                    mp[x - 1, y - 1] = 'O';
                    bool flag = true;
                    for (int j = 0; j < 3; j++)
                    {
                        if (mp[x - 1, j] != 'O')
                        {
                            flag = false;
                        }
                    }
                    if (flag) return 2;
                    flag = true;
                    for (int j = 0; j < 3; j++)
                    {
                        if (mp[j, x - 1] != 'O')
                        {
                            flag = false;
                        }
                    }
                    if (flag) return 2;
                    flag = true;
                    if ((x - 1 == 0 && y - 1 == 0) || (x - 1 == 1 && y - 1 == 1) || (x - 1 == 2 && y - 1 == 2))
                    {
                        for (int j = 0; j < 3; j++)
                        {
                            if (mp[j, j] != 'O'){
                                flag = false;
                            }
                        }
                        if (flag) return 2;
                    }
                    flag = true;
                    if ((x - 1 == 0 && y - 1 == 2) || (x - 1 == 1 && y - 1 == 1) || (x - 1 == 2 && y - 1 == 0))
                    {
                        for (int j = 0; j < 3; j++)
                        {
                            if (mp[j, 2 - j] != 'O'){
                                flag = false;
                            }
                        }
                        if (flag) return 2;
                    }
                }
            }
            return 0;
        }

        static void write(int x)
        {
            for(int i=0;i<x;i++)
            {
                Console.WriteLine("Case {0}:", i + 1);
                if (record[i] == 1) Console.WriteLine("Play1 win");
                else if (record[i] == 2) Console.WriteLine("Play2 win");
                else Console.WriteLine("No winner");
            }
            Console.WriteLine("请输入任意键继续\n");
            Console.ReadKey();
        }

        static void Main(string[] args)
        {

            //  char ch[5][5]={0};
            // int a[5][5]={0},k[1000000];
            int k = 0;
            int order = 0;
            while(true) {
                Console.Clear();
                Console.WriteLine("请输入指令");
                Console.WriteLine("1.开始游戏");
                Console.WriteLine("2.打印记录");
                Console.WriteLine("3.游戏结束");
                order = int.Parse(Console.ReadLine());
                if (order == 1)
                {
                    record[k++] = game();
                }
                else if (order == 2) write(k);
                else break;
            }
            Console.Read();
        }
    }
}
